package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目Controller类
 *
 * @Description NursingProjectController
 * @Author Lwj
 * @Date 2024-08-23-10:11
 */
@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * @param name     护理项目名称
     * @param status   状态：0-禁用，1-启用
     * @param pageNum  当前页码
     * @param pageSize 每页显示数量
     * @return 护理项目列表
     */
    @GetMapping
    @ApiOperation(value = "分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "状态：0-禁用,1-启用") Integer status,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return success(nursingProjectPageInfo);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto 护理项目数据传输对象
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增护理项目")
    public ResponseResult addNursingProject(
            @ApiParam(value = "新增护理项目传参json", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {
        log.info("新增护理项目{}", nursingProjectDto);
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询护理
     *
     * @param id 查询护理的id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理")
    public ResponseResult<NursingProjectVo> getNursingProjectById(
            @ApiParam(value = "查询护理的id", required = true) @PathVariable String id) {
        log.info("根据id查询护理{}", id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getNursingProjectById(id);
        return success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     *
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "编辑护理项目")
    public ResponseResult updateNursingProject(
            @RequestBody NursingProjectDto nursingProjectDto) {
        log.info("编辑护理项目");
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 删除护理项目
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目")
    public ResponseResult deleteNursingProject(
            @ApiParam(value = "要删除的id") @PathVariable Long id) {
        log.info("删除护理项目{}", id);
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    /**
     * 项目启用禁用
     *
     * @param id
     * @param status 状态（0：禁用，1：启用
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "项目启用禁用")
    public ResponseResult ResetStatus(
            @ApiParam(value = "要修改项目状态的id") @PathVariable Long id,
            @ApiParam(value = "状态（0：禁用，1：启用）") @PathVariable int status) {
        log.info("项目启用禁用{}-{}", id, status);
        nursingProjectService.ResetStatus(id, status);
        return success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProject() {
        log.info("查询所有护理项目!");
        List<NursingProjectVo> nursingProjectVo = nursingProjectService.getAllNursingProject();
        return success(nursingProjectVo);
    }

}
